package com.chainyoung.component_tmperson.ui.mvp.presenter;

import com.chainyoung.common.appcommon.entity.UploadFile;
import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.bean.UserInfo;
import com.chainyoung.common.exception.ApiException;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.common.utils.UpLoadUtils;
import com.chainyoung.component_tmperson.entity.WalletFinancing;
import com.chainyoung.component_tmperson.ui.mvp.contract.UpdateUserInfoContract;
import com.chainyoung.component_tmperson.ui.mvp.contract.WalletFinancingMangeContract;

import java.util.List;
import java.util.TreeMap;

import javax.inject.Inject;

import okhttp3.RequestBody;

import static com.chainyoung.common.constant.LibConstant.NO_RESULT_ERRORCODE;

public class WalletFinancingMangePresenter extends BasePresenter<WalletFinancingMangeContract.Model, WalletFinancingMangeContract.View> {

    @Inject
    public WalletFinancingMangePresenter(WalletFinancingMangeContract.Model model, WalletFinancingMangeContract.View rootView) {
        super(model, rootView);
    }


    public void getWalletFinancingList(TreeMap<String, Object> map) {

        addSubscribe(mModel.getWalletFinancingList(map)
                .compose(RxUtils.<List<WalletFinancing>>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<List<WalletFinancing>>(mView, false) {
                    @Override
                    public void onNext(List<WalletFinancing> data) {
                        mView.onGetAllFinancingList(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        if (e instanceof ApiException) {
                            if (((ApiException) e).getErrorCode().equals(NO_RESULT_ERRORCODE)) {
                                mView.onGetAllFinancingList(null);
                                return;
                            }
                        }
                        mView.onGetAllFinancingListFailed();
                        super.onError(e);
                    }
                }));
    }


}


